package pacman.entries.pacman.ml.features;

import pacman.game.Game;
import pacman.game.Constants.DM;

public class PowerPillDistance extends FeatureExtractor {
	
	public PowerPillDistance(float arg) {}
	@Override
	protected float Extract(Game game) {
		
		if (game.getNumberOfActivePowerPills() == 0)
			return 0;
		
		int[] activePowerPills = game.getActivePowerPillsIndices();
		int playerLocation = game.getPacmanCurrentNodeIndex();
		
		float bestDistance = Float.MAX_VALUE;
		for (int i = 0; i < activePowerPills.length; i++) {
			float distance = (float)game.getDistance(playerLocation, activePowerPills[i], DM.PATH);
			if (distance < bestDistance)
				bestDistance = distance;
		}
		
		return FeatureExtractor.FeatureDistance(bestDistance);
	}

}
